// Learn TypeScript:
//  - hwxps://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Awxribute:
//  - hwxps://docs.cocos.com/creator/manual/en/scripting/reference/awxributes.html
// Learn life-cycle callbacks:
//  - hwxps://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class wxAdManager extends cc.Component {

    public static banner_id = "";
    public static video_id = "";
    public static interstitial_id = "";
    public static grid_id = "";

    onLoad() {
        wxAdManager.getInterface().initSDK();
        cc["ad_manager"] = wxAdManager.getInterface(); // 全局对象 给 JS用
    }

    start() {

    }

    static wx_ad_interface = null;
    public static getInterface(): wxAdManager {
        if (wxAdManager.wx_ad_interface == null) {
            wxAdManager.wx_ad_interface = new wxAdManager();
            wxAdManager.getInterface().initSDK();
        }
        return wxAdManager.wx_ad_interface;
    }

    /****************************************************
     *                  广告调用接口
     ****************************************************/

    show_my_ad(type: number, sid: number = 0) {

    }
    close_my_ad(type: number) {

    }

    //#################################激励视频
    public show_RewardVideoAd(succ: Function, fail: Function = null) {
        this.ShowMyVideoAds((cb: number) => {
            if (cb == 1) {
                succ && succ();
            } else {
                fail && fail();
            }
        });
    }

    //################################### BANNER
    _is_banner_showing = false;
    show_BannerAd() {
        if (this._is_banner_showing == true) {
            return;
        }
        this._is_banner_showing = true;
        this.ShowBanner();
    }
    close_BannerAd() {
        if (this._is_banner_showing == false) {
            return;
        }
        this._is_banner_showing = false;
        this.CloseBanner();
    }

    //##############################  插屏
    show_InterAd(sid: number = 0) {
        this.showInterstitialAd();
    }

    //##############################  启动更多游戏 界面
    show_moreGame_ui() {

    }

    //############################## 更多游戏 按钮
    show_moreGame_button() {

    }

    close_moreGame_button() {

    }

    // ############################# 游戏分享
    GameShare(fun: any) {

    }

    // ############################# 录屏分享 (头条专属)
    StartRecordScreen() {

    }

    //停止录屏
    StopRecordScreen() {

    }

    //分享录制的视频
    ShareRecordScreen(cb = null) {

    }

    show_native_interAd(sid: number = 0) {

    }

    show_native_iconAd() {

    }

    close_native_iconAd() {

    }

    /***********************************************
     *              震动
     ***********************************************/
    is_vibrate: boolean = true;
    public set_vibrate(v: boolean) {
        this.is_vibrate = v;
    }
    public get_vibrate(): boolean {
        return this.is_vibrate;
    }

    public vibrate_short() {
        if (this.is_vibrate) {
            this.vibrateShort()
        }
    }

    public vibrate_long() {
        if (this.is_vibrate) {
            this.vibrateLong();
        }
    }

    /************************************************
     *              初始化
     ************************************************/
    wx = null;
    count_auto_ad = null;
    _time_auto_ad = null;

    static wx_ver = null;
    static screen_width = null;
    static screen_height = null;

    static query: object = null; ////////启动小游戏的 query 参数

    static count = 0;

    public initSDK() {
        if (this.is_wx() == false) { ////// 不是微信
            return;
        }

        if (this.wx) {
            return;
        }
        this.wx = window["wx"];
        console.log("######## 初始化 SDK########");

        let sysinfo = this.wx.getSystemInfoSync();
        wxAdManager.wx_ver = sysinfo.SDKVersion;  // 微信版本
        wxAdManager.screen_width = sysinfo.windowWidth;
        wxAdManager.screen_height = sysinfo.windowHeight;
        console.log("sysinfo##############################", sysinfo);

        let launchOptions = this.wx.getLaunchOptionsSync();
        wxAdManager.query = launchOptions.query;

        console.log("launchOptions#########################", launchOptions);

        // this.init_InterstitialAd(); // 插屏广告初始化
        // this.initBannerAds();  // 横幅广告 初始化
        // this.init_gridAd();
        // this.initMyVideoAds();
    }

    is_wx(): boolean {
        return cc.sys.platform === cc.sys.WECHAT_GAME;
    }

    /****************************************************
     *          视频广告
     ****************************************************/
    video_ad = null;
    videoAd_callback = null;
    initMyVideoAds() {
        if (this.wx == null) return;

        this.video_ad = this.wx.createRewardedVideoAd({ adUnitId: wxAdManager.video_id });
        this.video_ad.onLoad((res) => { // 监听激励视频广告加载事件。
            console.log(res);
        });
        this.video_ad.onError((res) => { // 监听激励视频错误事件。
            if (this.videoAd_callback) {
                this.videoAd_callback(0);
                this.videoAd_callback = null;
            }
        });
        this.video_ad.onClose((res) => { // 监听用户点击 关闭广告 按钮的事件。
            if (res.isEnded == true) {
                if (this.videoAd_callback) {
                    this.videoAd_callback(1);
                    this.videoAd_callback = null;
                }
            } else {
                if (this.videoAd_callback) {
                    this.videoAd_callback(0);
                    this.videoAd_callback = null;
                }
            }
        });
    }

    ShowMyVideoAds(cb: Function) {
        if (this.wx == null) {
            cb(1);
            return;
        }

        // if (wxAdManager.video_id == null || wxAdManager.video_id == '') {
        //     cb(1);
        //     this.showToast("广告功能暂时无法使用");
        //     return;
        // }

        console.log("*********** 启动视频广告");

        if (this.video_ad != null) {
            this.videoAd_callback = cb;
            let res = this.video_ad.show();
            console.log(res);
        } else {
            cb(0);
        }
    }

    /***************************************************
     *         关闭横幅广告
     ***************************************************/
    bannerAD = null;
    initBannerAds() {
        if (this.wx == null) {
            return;
        }

        if (wxAdManager.banner_id == null || wxAdManager.banner_id == "") {
            return;
        }

        this.bannerAD = this.wx.createBannerAd({
            adUnitId: wxAdManager.banner_id,
            adIntervals: 30, // 自动刷新频率不能小于30秒
            style: {
                left: wxAdManager.screen_width / 2 - 150,
                top: wxAdManager.screen_height - 90,
                width: 300
            }
        });
        this.bannerAD.onLoad((res) => { // 监听 banner 广告加载事件。
            console.log(res);
            this.bannerAD.hide();
        });
        this.bannerAD.onResize((res) => { // 改变大小事件
            console.log(res);
            this.bannerAD.style.left = wxAdManager.screen_width / 2 - res.width / 2;
            this.bannerAD.style.top = wxAdManager.screen_height - res.height;
        });
        this.bannerAD.onError((res) => { // 监听 banner 广告错误事件。
            console.log(res);
        });
    }

    // ShowBannerAds() {
    //     if (this.bannerAD == null) {
    //         this.initBannerAds();
    //         return;
    //     }
    //     this.bannerAD.show();
    // }

    // CloseBannerAds() {
    //     if (this.bannerAD == null) {
    //         return;
    //     }
    //     this.bannerAD.hide();
    // }

    ShowBanner() {
        if (this.bannerAD == null) {
            this.initBannerAds();
            return;
        }
        this.bannerAD.show();
    }

    CloseBanner() {
        if (this.bannerAD == null) {
            return;
        }
        this.bannerAD.hide();
    }

    /************************************************************
     *    					插屏广告	
     ************************************************************/
    interstitialAd = null;
    init_InterstitialAd() {
        if (this.wx == null) return;
        if (wxAdManager.interstitial_id == null || wxAdManager.interstitial_id == "") {
            return;
        }

        this.interstitialAd = this.wx.createInterstitialAd({ adUnitId: wxAdManager.interstitial_id })
        this.interstitialAd.onLoad(() => {
            console.log('插屏 广告加载成功')
        })
        this.interstitialAd.onError(err => {
            console.log(err)
        })
        this.interstitialAd.onClose(res => {
            console.log('插屏 广告关闭')
        })
    }

    showInterstitialAd() {
        if (this.interstitialAd == null) {
            this.init_InterstitialAd();
            return;
        }

        this.interstitialAd.show().catch((err) => {
            console.error(err)
        })
    }

    /*********************************************************
     *                    Grid 广告
     *********************************************************/
    GridAd = null;
    init_gridAd() {
        if (this.wx == null) return;
        if (wxAdManager.grid_id == null || wxAdManager.grid_id == "") {
            return;
        }

        this.GridAd = this.wx.createGridAd({
            adUnitId: wxAdManager.grid_id,
            adTheme: 'white',
            gridCount: 5,
            style: {
                left: wxAdManager.screen_width / 2 - 150,
                top: wxAdManager.screen_height - 110,
                width: 300,
                opacity: 0.8
            },
            adIntervals: 30, // 自动刷新频率不能小于30秒
        })

        this.GridAd.onError(err => {
            console.log(err)
        })

        this.GridAd.onLoad(() => {
            console.log('Grid 广告加载成功')
        })

        this.GridAd.onResize(res => {
            this.GridAd.style.width = 300;
            this.GridAd.style.left = wxAdManager.screen_width / 2 - 150;
        })
    }

    show_gridAd() {
        if (this.GridAd == null) {
            this.init_gridAd()
            return;
        }
        this.GridAd.show()
            .then(() => console.log('Grid 广告显示'))
            .catch(err => console.log(err));
    }

    hide_gridAd() {
        if (this.GridAd == null) {
            return;
        }
        this.GridAd.hide()
    }


    /**********************************************************
     *                    原生 广告
     **********************************************************/
    doShowNativeAd() {

    }

    /***********************************************************
     *                      震动
     ***********************************************************/
    // 长震动
    vibrateLong() {
        if (this.wx == null) {
            console.log("#################### 长震动");
            return;
        }
        this.wx.vibrateLong({
            type: "medium",
            success: function () { },
            fail: function () { },
        });
    }

    // 短震动
    vibrateShort() {
        if (this.wx == null) {
            console.log("#################### 短震动");
            return;
        }
        this.wx.vibrateShort({
            type: "heavy",
            success: function () { },
            fail: function () { },
        });
    }

    /*********************************************
     *          微信剪切板
     *********************************************/
    set_clipboard(str: string) {
        if (this.wx == null) {
            console.log("#################### 设置剪切板 : " + str);
            return;
        }

        this.wx.setClipboardData({
            data: str,
            success: function (res) {
                console.log(res)
            },
            fail: function (res) {
                console.error(res);
            }
        })
    }

    get_clipboard(cb: (str: string) => {}) {
        if (this.wx == null) {
            console.log("#################### 获得剪切板");
            cb("剪切板测试");
            return;
        }

        this.wx.getClipboardData({
            success: function (res) {
                console.log(res.data)
                cb(res.data);
            },
            fail: function (res) {
                console.error(res);
            }
        })
    }

    /**********************************************
     *                  提示
     **********************************************/
    showToast(text: string, time = 2000) {
        this.wx.showToast({
            title: text,
            icon: 'success',
            duration: time
        })
    }

    //////////////////////////////////////// 模拟信息
    _moni_userinfo = { "encryptedData": "zW3CRDjUVdWh5qlqOlVXMF39GF2XS23phxJ80AzfxwBDI4x8oCI9zzcTXOzJ46X96pR1lZdnvF1OIDy20z65T4mfr4vz6RKRf5oCJkRC65QB8b6lFrIQKY/77YwgYReagVKMfe5a56Zs/DgAwTt95AbiStIKmptrlmjk7UzlCgfqBBVgyMnqoKHEL/QFKkijIgBN4wprnHoPi1VPs5EUCOQYDFqGe4qfR9NGsdkQD8lyDXgta+Je/moCCejMIs7P4VWeHsWdnhOI7MplHK83gfHUXAkzC0Yk5aIB30oUA9Hs26F3ULukkPmucgidBFXbSBOxf1K0JKDgbTMetPU+xLjU2zw38NGnp+3SRI1/xrFQnUXjGjmsbrTA2LrVwRNTAsmaBOQ/YOeW+8x73MtfIQF06O6QzrWhWbCET4pqZuwqm5wBTl9KrKDgT9a4cWi/NikX5JZaCHsuN1cuaCvzoQ==", "iv": "GTHGeazFfDTk8zlGGyWILQ==", "signature": "1ad4ca15aa344e838f4a4c96f22d46a3edae2211", "userInfo": { "nickName": "曲荣君", "gender": 0, "language": "zh_CN", "city": "", "province": "", "country": "", "avatarUrl": "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoSAkYBe5JBUmFydu6Av0IbkoVkdfhbdaER3VK124N21EHIntNrDP35NcYDWMgDNAibAFpszVsQ9gA/132" }, "rawData": "{\"nickName\":\"曲荣君\",\"gender\":0,\"language\":\"zh_CN\",\"city\":\"\",\"province\":\"\",\"country\":\"\",\"avatarUrl\":\"https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoSAkYBe5JBUmFydu6Av0IbkoVkdfhbdaER3VK124N21EHIntNrDP35NcYDWMgDNAibAFpszVsQ9gA/132\"}", "errMsg": "getUserInfo:ok" };
    _moni_login_data = { "errMsg": "login:ok", "code": "cd1Bxq000irF7Q1zCA300AwT9v1Bxq0B" };

    /***************************************************
     *              声明周期
     ***************************************************/
    _on_show_event: Map<string, Function> = null;
    _on_hide_event: Map<string, Function> = null;
    init_smzq() {
        this._on_show_event = new Map();
        this._on_hide_event = new Map();
        this.wx.onShow(() => {
            this._on_show_event.forEach((value, key) => {
                value && value();
            });
        });

        this.wx.onHide(() => {
            this._on_hide_event.forEach((value, key) => {
                value && value();
            });
        });
    }

    add_show_event(name: string, event: Function) {
        this._on_show_event.set(name, event);
    }

    add_hide_event(name: string, event: Function) {
        this._on_hide_event.set(name, event);
    }

    del_show_event(name: string) {
        this._on_show_event.delete(name);
    }

    del_hide_event(name: string) {
        this._on_hide_event.delete(name);
    }

    /******************************************************
     *      登录  succ(userInfo , login) , fail(err)
     *******************************************************/
    userinfo: UserInfo = null;
    get_userInfo(succ: Function, fail: Function = null) {
        if (this.is_wx() == false) {
            cc.error("不是微信平台");
            this.userinfo = new UserInfo();
            this.userinfo.init(this._moni_userinfo);
            succ(this._moni_userinfo);
            return;
        }

        var self = this;
        let width = cc.winSize.width;
        let height = cc.winSize.height;
        this.wx.getSetting({
            success(res) {
                if (res.authSetting['scope.userInfo']) {
                    console.log(">>>>>>>>>>>>wx.getUserInfo");
                    // 已经授权，可以直接调用 getUserInfo 获取头像昵称
                    self.wx.getUserInfo({
                        success: function (res) {
                            console.log("已经授过权了===>", JSON.stringify(res))
                            // cc.director.emit("yishouquan", { info: res['userInfo'] })

                            self.userinfo = new UserInfo();
                            self.userinfo.init(res);

                            succ && succ(res);
                        }
                    })
                } else {
                    console.log(">>>>>>>>>>>>wx.createUserInfoButton");
                    // cc.director.emit("weishouquan")
                    // 否则，先通过 wx.createUserInfoButton 接口发起授权
                    let button = self.wx.createUserInfoButton({
                        type: 'text',
                        text: '',
                        style: {
                            left: 0,
                            top: 0,
                            width: width,
                            height: height,
                            backgroundColor: '#00000000',//最后两位为透明度
                            color: '#ffffff',
                            fontSize: 20,
                            textAlign: "center",
                            lineHeight: height,
                        }
                    })
                    button.onTap((res) => {
                        // 用户同意授权后回调，通过回调可获取用户头像昵称信息
                        console.log("onTap uinfo: ", res);
                        if (res.userInfo) {
                            console.log("wxLogin auth success", res);
                            self.wx.showToast({ title: "授权成功" });

                            self.userinfo = new UserInfo();
                            self.userinfo.init(res);

                            succ && succ(res);
                            button.destroy();
                        } else {
                            console.log("wxLogin auth fail", res);
                            self.wx.showToast({ title: "授权失败" });
                            fail && fail("授权失败  wx.createUserInfoButton");
                            button && button.destroy();
                        }
                    })
                }
            }
        })
    }

    public wxLogin(succ: wxLogin_callback, fail: Function = null) {
        if (this.is_wx() == false) {
            cc.error("不是微信平台");
            succ(this._moni_login_data);
            return;
        }

        this.wx.login({
            success(res) {
                console.log("wx login========>code", JSON.stringify(res))
                succ && succ(res)
            }, fail(res) {
                this.wx.showToast({ title: "登录失败" });

                fail && fail("登录失败 wx.login");
            }
        })
    }

    public exitGame() {
        if (this.is_wx() == false) {
            cc.error("不是微信平台 , 退出游戏");
            return;
        }

        this.wx.exitMiniProgram({
            success: function () {
                console.log("游戏已关闭");
            }
        });
    }

    /*********************************************************
     *                    微信新规  (获取头像昵称之前)
     *********************************************************/
    ////// 显示 隐私页面
    _resolve: Function = null;
    show_yinsi(succ: Function, fail: Function) {
        if (this.is_wx() == false) { ////// 不是微信
            console.log("show_yinsi 不是微信");
            succ && succ();
            return;
        }

        if (!this.wx.requirePrivacyAuthorize) {
            console.log("没有找到 wx.requirePrivacyAuthorize()");
            succ && succ();
            return;
        }

        console.log("运行 wx.requirePrivacyAuthorize()");

        this.wx.requirePrivacyAuthorize({
            success: res => {
                console.log("show_yinsi 成功");
                succ && succ();
            },
            fail: () => {
                console.log("show_yinsi 失败");
                fail && fail();
            },
            complete: () => { }
        })
    }

    /********************************************************
     *              视频 播放
     ********************************************************/
    video = null;
    play_video(url: string, ended_cb: Function) {
        if (this.is_wx() == false) { ////// 不是微信
            return;
        }

        // this.showToast(url, 10000);

        let width = wxAdManager.screen_width;
        let height = wxAdManager.screen_width;
        this.video = this.wx.createVideo({
            src: url,
            x: 0,
            y: height * 0.35,
            width: width,
            // height: width * 9 / 16
            height: width
        });

        this.video.onEnded(() => {
            this.close_play_video();
            ended_cb && ended_cb();
        });
    }

    close_play_video() {
        if (this.video) {
            this.video.destroy();
            this.video = null;
        }
    }

    /*************************************************
     *          分享到  朋友圈
     *************************************************/
    share_to_pengyouquan(succ: Function) {
        if (this.is_wx() == false) { ////// 不是微信
            return;
        }
        if (this.wx.showShareMenu == null) {
            return;
        }
        this.wx.showShareMenu({
            withShareTicket: true,
            menus: ['shareAppMessage', 'shareTimeline'],
            success: function (res) {
                console.log('分享朋友圈 成功');
                console.log('success ==' + JSON.stringify(res));
                succ && succ()
            },
        })
    }

    /*************************************************
     *    简单 分享 (默认配置)  _query=分享参数(key1=val1&key2=val2)
     *************************************************/
    easy_fenxiang(img_url: string, _query: string, succ: Function) {
        this.wx.shareAppMessage({
            query: _query,
            imageUrl: img_url
        });

        console.log('拉起分享');
        succ && succ();
    }

    /************************************************
     *              微信 截屏分享
     *  title= 分享标题 , _query=分享参数(key1=val1&key2=val2)   rect=屏幕区域
     ************************************************/
    jieping_fenxiang(title: string, _query: string, succ: Function, rect: cc.Rect = null) {
        if (this.is_wx() == false) { ////// 不是微信
            return;
        }

        //@ts-ignore
        let sw = canvas.width;
        //@ts-ignore
        let sh = canvas.height;

        let cs = null;
        if (rect == null) {
            cs = { //
                destWidth: sw / 2,
                //@ts-ignore
                destHeight: sh / 2,
                fileType: 'jpg',
                quality: 1.0
            }
        } else {
            cs = {
                x: Math.floor(sw * rect.x),
                y: Math.floor(sh * rect.y),
                width: Math.floor(sw * rect.width),
                height: Math.floor(sh * rect.height),
                //@ts-ignore
                destWidth: Math.floor(sw * rect.width / 2),
                //@ts-ignore
                destHeight: Math.floor(sh * rect.height / 2),
                fileType: 'jpg',
                quality: 1.0
            }
        }

        this.wx.shareAppMessage({
            title: title,
            //@ts-ignore
            imageUrl: canvas.toTempFilePathSync(cs),
            query: _query,
        });

        console.log('拉起分享 成功');
        succ && succ()
    }

    /********************************************
     *          截屏 保存到相册 ,  rect=屏幕区域
     ********************************************/
    jieping_save_xiangce(succ: Function, fail: Function, rect: cc.Rect = null) {
        if (this.is_wx() == false) { ////// 不是微信
            succ && succ();
            return;
        }
        let self = this;

        //@ts-ignore
        let sw = canvas.width;
        //@ts-ignore
        let sh = canvas.height;

        let cs = null;
        if (rect == null) {
            cs = { //
                destWidth: sw / 2,
                //@ts-ignore
                destHeight: sh / 2,
                fileType: 'jpg',
                quality: 1.0
            }
        } else {
            cs = {
                x: Math.floor(sw * rect.x),
                y: Math.floor(sh * rect.y),
                width: Math.floor(sw * rect.width),
                height: Math.floor(sh * rect.height),
                //@ts-ignore
                destWidth: Math.floor(sw * rect.width / 2),
                //@ts-ignore
                destHeight: Math.floor(sh * rect.height / 2),
                fileType: 'jpg',
                quality: 1.0
            }
        }

        let fun = () => {
            this.wx.saveImageToPhotosAlbum({
                //@ts-ignore
                filePath: canvas.toTempFilePathSync(cs),
                success: function () {
                    succ && succ();
                },
                fail: function () {
                    fail && fail();
                }
            });
        }

        this.wx.getSetting({
            success(res) {
                if (res.authSetting['scope.writePhotosAlbum']) { /// 已有权限

                    console.log("有权限  scope.writePhotosAlbum");

                    fun();
                } else { // 没有权限

                    console.log("没有权限  scope.writePhotosAlbum");

                    self.wx.authorize({
                        scope: 'scope.writePhotosAlbum',
                        success() {
                            console.log("申请权限成功  scope.writePhotosAlbum");
                            fun();
                        },
                        fail(e) {
                            console.log("申请权限失败  scope.writePhotosAlbum ", e);
                            fail && fail();
                        }
                    })
                }
            }
        })


    }

    /***********************************************
     *          跳转到其他 APP
     ***********************************************/
    goto_miniProgram(succ: Function = null) {
        this.wx.navigateToMiniProgram({
            appId: 'wxa72b940a2ab2b883',
            path: 'pages/chatBot/chatBot',
            extraData: {},
            envVersion: 'trial',
            success(res) {
                // 打开成功
                succ && succ();
            }
        })
    }

    /***********************************************
     *          创建 游戏圈 按钮
     ***********************************************/
    gameClubButton = null; ///// 游戏圈 按钮对象
    is_showGameClub = false; ////是否显示游戏圈按钮

    show_gameClubButton(rect: cc.Rect) {
        if (this.is_wx() == false || this.wx.createGameClubButton == null || rect.x >= 1 || rect.y >= 1) {
            // cc.log("========show_gameClubButton======== " , rect);
            return;
        }

        if (this.is_showGameClub == true) return;
        this.is_showGameClub = true;

        if (this.gameClubButton) {
            this.gameClubButton.show();
            return;
        }


        //@ts-ignore
        let sw = wxAdManager.screen_width;
        //@ts-ignore
        let sh = wxAdManager.screen_height;

        this.gameClubButton = this.wx.createGameClubButton({
            icon: 'light',
            style: {
                left: Math.floor(sw * rect.x),
                top: Math.floor(sh * rect.y),
                width: Math.floor(sw * rect.width),
                height: Math.floor(sh * rect.height)
            }
        })

        this.gameClubButton.show();

        // console.log("游戏圈按钮@@@@@@@@@@@@@@@@@@@@ ", rect, {
        //     left: sw * rect.x,
        //     top: sh * rect.y,
        //     width: sw * rect.width,
        //     height: sh * rect.height
        // });
    }

    hide_gameClubButton() {
        if (this.is_wx() == false) {
            // cc.log("========hide_gameClubButton========");
            return;
        }

        if (this.is_showGameClub == false) return;
        this.is_showGameClub = false;

        if (this.gameClubButton) {
            this.gameClubButton.hide();
        }
    }
}

/////// 微信用户信息
export class UserInfo {
    encryptedData = null;
    iv = null;
    signature = null;

    rawData = null;
    errMsg = null;

    nickName = "微信用户";
    gender = null;
    language = null;
    city = null;
    province = null;
    country = null;
    avatarUrl = "";

    public init(d: any) {
        this.encryptedData = d["encryptedData"];
        this.iv = d["iv"];
        this.signature = d["iv"];
        this.rawData = d["rawData"];
        this.errMsg = d["errMsg"];

        this.nickName = d["userInfo"]["nickName"];
        this.gender = d["userInfo"]["language"]
        this.city = d["userInfo"]["city"];
        this.province = d["userInfo"]["province"];
        this.country = d["userInfo"]["country"];
        this.avatarUrl = d["userInfo"]["avatarUrl"];
    }
}


export interface wxLogin_data {
    errMsg: string;
    code: string;
}

export interface wxLogin_callback {
    (wd: wxLogin_data): void;
}
